package com.yanqu.road.server.cmd.activity.feast.pvp;

import com.yanqu.road.entity.activity.feast.config.ShanHeFeastConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ShanHeFeastProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.activity.feast.CrossFeastMgr;
import com.yanqu.road.server.manager.activity.feast.activity.CrossFeastActivity;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_CROSS_SHAN_HE_FEAST_PVP_PING, desc = "心跳")
public class CrossFeastPvpPingCmd extends CrossCommand {

    private int activityId;

    private int type;

    private long playerId;


    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ShanHeFeastProto.FeastPvpPingReqMsg reqMsg = ShanHeFeastProto.FeastPvpPingReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        type = reqMsg.getType();
        playerId = packet.getPlayerId();
        return true;
    }


    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossFeastActivity activity = CrossFeastMgr.getActivity(activityId);
        if (activity == null) {
            ret = GameErrorCode.E_SHAN_HE_FEAST_ACTIVITY_NOT_FOUND;
            return;
        }
        ShanHeFeastConfig config = activity.getConfig();
        if (config == null) {
            ret = GameErrorCode.E_SHAN_HE_FEAST_PVP_CONFIG_NOT_FOUND;
            return;
        }
        ret = activity.pingByCmd(playerId, type);
    }

    @Override
    public void sendData() {

    }
}
